;; LTDL_LIBRARY_PATH=/opt/local/lib
;; GUILE_LOAD_PATH=.

;;(import (srfi srfi-1))

(import (rnrs)
        (grid-gen common)
        (srfi srfi-1)
)

(module-on fortran77)
(module-on HD)

;;(module-on Lax-Friedrichs)

(module-on Roe)

(module-on Einfeldt)
;;(module-on Harten2)

(module-on Osher)

(module-on grid)

;;(Harten2:set-eps! 100.0)

(define tim (comp-float "tim" 0.0))
(define tau (comp-float "tau"))

(define grid-dims '(1000))

(define xmin (comp-float "xmin"  0.0))
(define xmax (comp-float "xmax"  1.0))

(define tmax (comp-float "tmax" 0.18))

(define rho0 (comp-float "rho0"  1.0))
(define p0   (comp-float "p0"    1.0))
(define u0   (comp-float "u0"    0.0))

(define rho1 (comp-float "rho1"  1.0))
(define p1   (comp-float "p1"    3.0))
(define u1   (comp-float "u1"    0.0))

(define cour  (comp-float "cour" 0.1))

(define gr (grid:cart grid-dims))

(define grdf (lambda (x y z)
  (list `(+ ,xmin (* (- ,xmax ,xmin) 0.25 (- (** 5.0 ,x) 1.0))) y z)
))

(define grdf0 (lambda (x y z)
  (list `(+ ,xmin (* (- ,xmax ,xmin) ,x)) y z)
))

(gr 'set-geom grdf0)

(gr 'add-corr 'err)

(code-gen "shockROE"
  (beg
    (gr 'init-grid)

    (gr 'init (if (< (gr 'x) 0.5) rho1 rho0)
              (if (< (gr 'x) 0.5) p1 p0)
              (if (< (gr 'x) 0.5) u1 u0)
    )

    (do-while (< tim tmax)
      (if (= (gr 'err) 0)
        (beg
          (gr 'CFL cour)
          (if (> (+ (gr 'tau) tim) tmax)
              (set-val (gr 'tau) (- tmax tim))
          )
        )
      )
      (do-every 1 'sec (print "t=" tim))
      (gr 'calc)
      (if (= (gr 'err) 0)
          (set-val tim (+ tim (gr 'tau)))
          (beg
            (set-val (gr 'tau) (* 0.5 (gr 'tau)))
            (print "new Tau=" (gr 'tau))
          )
      )
    )
    (gr 'save-all "roe.dat")
  )
)

(display "\n")
